options ps=MAX ls=MAX nodate nonumber nocenter;

*options nonotes nosource nosource2 errors=0;
*ods listing;
*proc printto print="C:\Users\BANQUE0_O_GODECHO\Documents\res\segreg\out.txt";
*run;

* CHANGING THE WORK DIRECTORY; 
libname user "C:\Users\Public\Documents\Sas_work_dir";
libname wflow "C:\Users\Public\Documents\Results\Worker_Flows";
libname lyof "C:\Users\Public\Documents\Results\layoffs";

*libname me "C:\Users\BANQUE0_O_GODECHO\Documents\bdsas";
libname rec "C:\Users\Public\Documents\Results\Segreg\";
libname est_comp "C:\Users\Public\Documents\Results\Establishment_Composition\";


*libname rec "C:\Users\Public\Documents\Test_data";
libname test "C:\Users\Public\Documents\Test_data";
libname psid "C:\Users\Public\Documents\Results\Pseudo_id";


libname lifi19 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2019";
libname lifi18 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2018";
libname lifi17 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2017";
libname lifi16 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2016";
libname lifi15 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2015";
libname lifi14 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2014";
libname lifi13 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2013";
libname lifi12 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_LIFI_2012";
libname lifi11 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2011";	
libname lifi10 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2010";
libname lifi09 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2009";
libname lifi08 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2008";
libname lifi07 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2007";
libname lifi06 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2006";
libname lifi05 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2005";
libname lifi04 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2004";
libname lifi03 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2003";
libname lifi02 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2002";
libname lifi02 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2002";
libname lifi01 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2001";
libname lifi00 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_2000";
libname lifi99 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1999";
libname lifi98 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1998";
libname lifi97 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1997";
libname lifi96 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1996";
libname lifi95 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1995";
libname lifi94 "\\casd.fr\casdfs\Projets\INEPROG\Data\LIFI_Enqu�te LIFI_1994";


*libname test "P:\Test_data";
libname po1994 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1994";
libname po1995 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1995";
libname po1996 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1996";
libname po1997 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1997";
libname po1998 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1998";
libname po1999 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_1999";
libname po2000 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2000";
libname po2001 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2001";
libname po2002 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2002";
libname po2003 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2003";
libname po2004 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2004";
libname po2005 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2005";
libname po2006 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2006";
libname po2007 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2007";
libname po2008 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2008";
libname po2009 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2009";
libname po2010 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2010";
libname po2011 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2011";
libname po2012 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2012";
libname po2013 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2013";
libname po2014 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2014\R�gions";
libname po2015 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2015\R�gions";
libname po2016 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2016\R�gions";
libname po2017 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2017\R�gions";
libname po2018 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2018";
libname po2019 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2019";

libname pi2012 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2012\Ile de France";
libname pi2013 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2013\Ile de France";
libname pi2014 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2014\D�partements";
libname pi2015 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2015\D�partements";
libname pi2016 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2016\D�partements";
libname pi2017 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Postes_2017\D�partements";


*BE: Mining, Manufacturing and Energy;
* F: Construction;
* A&G: A:Agriculture & G:Trade;
* H: Transportation;
* I: Accomodation;
* J & : J. Info. & Comm & R: Leisure;
* K: Finance;
* LM: Real Estate and professional services;
* N: Support services;
* OPQ: State, teaching and health; 
* STU: Other;

proc format; 

	value $ZEAT
	 "75","77","78","91"-"95"="1.IledeFrance"
	"08","10","51","52","02","60","80","27","76","18","28","36","37","41","45","14","50","61","21","58","71","89"="2.BassinParisien"
	"59","62"="3.Nord"
	"54","55","57","88","67","68","25","39","70","90"="4.Est"
	"44","49","53","72","85","22","29","35","56","16","17","79","86"="5.Ouest"
	"24","33","40","47","64","09","12","31","32","46","65","81","82","19","23","87"="7.SudOuest"
	"01","07","26","38","42","69","73","74","03","15","43","63"="8.CentreEst"
	"11","30","34","48","66","04","05","06","13","83","84","20","2A","2B","2a","2b"="9.M�diterrrann�e";



	value $ind08_sectagg
		"05"-"39"="BE"
		"41"-"43"="F"
		"01"-"03","45"-"47"="A&G"
		"49"-"53"="H"
		"55"-"56"="I"
		"58"-"63","90"-"93"="J&R"
		"64"-"66"="K"
		"68"-"75"="LM"
		"77"-"82"="N"
		"84"-"88"="OPQ"
		"","94"-"99"="STU"
		OTHER="STU";

	value $naf03_naf08_
	"011A"="0111Z"
	"011C"="0111Z"
	"011D"="0113Z"
	"011F"="0122Z"
	"011G"="0121Z"
	"012A"="0141Z"
	"012C"="0143Z"
	"012E"="0146Z"
	"012G"="0147Z"
	"012J"="0144Z"
	"013Z"="0150Z"
	"014A"="0161Z"
	"014B"="8130Z"
	"014D"="0162Z"
	"015Z"="0170Z"
	"020A"="0129Z"
	"020B"="0220Z"
	"020D"="0240Z"
	"050A"="0311Z"
	"050C"="0321Z"
	"101Z"="0510Z"
	"102Z"="0520Z"
	"103Z"="0892Z"
	"111Z"="0610Z"
	"112Z"="0910Z"
	"120Z"="0721Z"
	"131Z"="0710Z"
	"132Z"="0729Z"
	"141A"="0811Z"
	"141C"="0811Z"
	"141E"="0811Z"
	"142A"="0812Z"
	"142C"="0812Z"
	"143Z"="0891Z"
	"144Z"="0893Z"
	"145Z"="0899Z"
	"151A"="0149Z"
	"151C"="1011Z"
	"151E"="1013A"
	"151F"="1013B"
	"152Z"="1020Z"
	"153A"="1031Z"
	"153C"="1032Z"
	"153E"="1039A"
	"153F"="1039B"
	"154A"="1041A"
	"154C"="1041B"
	"154E"="1042Z"
	"155A"="1051A"
	"155B"="1051B"
	"155C"="1051C"
	"155D"="1051D"
	"155F"="1052Z"
	"156A"="1061A"
	"156B"="1061B"
	"156D"="1062Z"
	"157A"="1091Z"
	"157C"="1092Z"
	"158A"="1071A"
	"158B"="1071B"
	"158C"="1071C"
	"158D"="1071D"
	"158F"="1072Z"
	"158H"="1081Z"
	"158K"="1082Z"
	"158M"="1073Z"
	"158P"="1083Z"
	"158R"="1084Z"
	"158T"="1086Z"
	"158V"="1085Z"
	"159A"="1101Z"
	"159B"="1101Z"
	"159D"="1101Z"
	"159F"="1102A"
	"159G"="1102B"
	"159J"="1103Z"
	"159L"="1104Z"
	"159N"="1105Z"
	"159Q"="1106Z"
	"159S"="1107A"
	"159T"="1107B"
	"160Z"="1200Z"
	"171A"="1310Z"
	"171C"="1310Z"
	"171E"="1310Z"
	"171F"="1310Z"
	"171H"="1310Z"
	"171K"="1310Z"
	"171M"="1310Z"
	"171P"="1310Z"
	"172A"="1320Z"
	"172C"="1320Z"
	"172E"="1320Z"
	"172G"="1320Z"
	"172J"="1320Z"
	"173Z"="1330Z"
	"174A"="1392Z"
	"174B"="1392Z"
	"174C"="1392Z"
	"175A"="1393Z"
	"175C"="1394Z"
	"175E"="1395Z"
	"175G"="1396Z"
	"176Z"="1391Z"
	"177A"="1419Z"
	"177C"="1439Z"
	"181Z"="1411Z"
	"182A"="1412Z"
	"182C"="1413Z"
	"182D"="1413Z"
	"182E"="1413Z"
	"182G"="1414Z"
	"182J"="1419Z"
	"183Z"="1320Z"
	"191Z"="1511Z"
	"192Z"="1512Z"
	"193Z"="1520Z"
	"201A"="1610A"
	"201B"="1610B"
	"202Z"="1621Z"
	"203Z"="1622Z"
	"204Z"="1624Z"
	"205A"="1629Z"
	"205C"="1629Z"
	"211A"="1711Z"
	"211C"="1712Z"
	"212A"="1721A"
	"212B"="1721B"
	"212C"="1721C"
	"212E"="1722Z"
	"212G"="1723Z"
	"212J"="1724Z"
	"212L"="1729Z"
	"221A"="3299Z"
	"221C"="5813Z"
	"221E"="5814Z"
	"221G"="5920Z"
	"221J"="5819Z"
	"222A"="1811Z"
	"222C"="1723Z"
	"222E"="1814Z"
	"222G"="1813Z"
	"222J"="1813Z"
	"223A"="1820Z"
	"223C"="1820Z"
	"223E"="1820Z"
	"231Z"="1910Z"
	"232Z"="1920Z"
	"233Z"="2013A"
	"241A"="2011Z"
	"241C"="2012Z"
	"241E"="2013B"
	"241G"="1910Z"
	"241J"="0891Z"
	"241L"="2016Z"
	"241N"="2017Z"
	"242Z"="2020Z"
	"243Z"="2030Z"
	"244A"="2110Z"
	"244C"="2120Z"
	"244D"="2120Z"
	"245A"="2041Z"
	"245C"="2042Z"
	"246A"="2051Z"
	"246C"="2052Z"
	"246E"="2053Z"
	"246G"="2059Z"
	"246J"="2680Z"
	"246L"="2059Z"
	"247Z"="2060Z"
	"251A"="2211Z"
	"251C"="2211Z"
	"251E"="2219Z"
	"252A"="2221Z"
	"252C"="2222Z"
	"252E"="2223Z"
	"252G"="2229A"
	"252H"="2229A"
	"261A"="2311Z"
	"261C"="2312Z"
	"261E"="2313Z"
	"261G"="2314Z"
	"261J"="2319Z"
	"261K"="2319Z"
	"262A"="2341Z"
	"262C"="2342Z"
	"262E"="2343Z"
	"262G"="2344Z"
	"262J"="2349Z"
	"262L"="2320Z"
	"263Z"="2331Z"
	"264A"="2332Z"
	"264B"="2332Z"
	"264C"="2332Z"
	"265A"="2351Z"
	"265C"="2352Z"
	"265E"="2352Z"
	"266A"="2361Z"
	"266C"="2362Z"
	"266E"="2363Z"
	"266G"="2364Z"
	"266J"="2365Z"
	"266L"="2369Z"
	"267Z"="2370Z"
	"268A"="2391Z"
	"268C"="2399Z"
	"271Y"="2410Z"
	"272A"="2451Z"
	"272C"="2420Z"
	"273A"="2431Z"
	"273C"="2432Z"
	"273E"="2433Z"
	"273G"="2434Z"
	"274A"="2441Z"
	"274C"="2442Z"
	"274D"="2442Z"
	"274F"="2443Z"
	"274G"="2443Z"
	"274J"="2444Z"
	"274K"="2444Z"
	"274M"="2445Z"
	"275A"="2451Z"
	"275C"="2452Z"
	"275E"="2453Z"
	"275G"="2454Z"
	"281A"="2433Z"
	"281C"="2512Z"
	"282C"="2529Z"
	"282D"="2521Z"
	"283A"="2530Z"
	"283B"="2530Z"
	"283C"="3311Z"
	"284A"="2550A"
	"284B"="2550B"
	"284C"="2550A"
	"285A"="2561Z"
	"285C"="2562A"
	"285D"="2562B"
	"286A"="2571Z"
	"286C"="2573B"
	"286D"="2573B"
	"286F"="2572Z"
	"287A"="2591Z"
	"287C"="2592Z"
	"287E"="2593Z"
	"287G"="2594Z"
	"287H"="2593Z"
	"287J"="2593Z"
	"287L"="2599A"
	"287N"="2599B"
	"287Q"="2571Z"
	"291A"="2811Z"
	"291B"="2812Z"
	"291D"="2812Z"
	"291E"="2813Z"
	"291F"="2812Z"
	"291H"="2815Z"
	"291J"="2815Z"
	"292A"="2821Z"
	"292C"="2822Z"
	"292D"="2822Z"
	"292F"="2825Z"
	"292H"="2829A"
	"292J"="2829A"
	"292L"="2829B"
	"292M"="2829B"
	"293A"="2830Z"
	"293C"="3312Z"
	"293D"="2830Z"
	"294A"="2841Z"
	"294B"="2849Z"
	"294C"="2824Z"
	"294D"="2790Z"
	"294E"="2849Z"
	"295A"="2891Z"
	"295B"="2892Z"
	"295D"="2892Z"
	"295E"="2893Z"
	"295G"="2894Z"
	"295J"="2895Z"
	"295L"="2894Z"
	"295M"="2896Z"
	"295N"="2573A"
	"295Q"="2899B"
	"295R"="2894Z"
	"296A"="2540Z"
	"296B"="2540Z"
	"297A"="2751Z"
	"297C"="2752Z"
	"300A"="2620Z"
	"300C"="2620Z"
	"311A"="2611Z"
	"311B"="2611Z"
	"311C"="3313Z"
	"312A"="2611Z"
	"312B"="2611Z"
	"313Z"="2611Z"
	"314Z"="2720Z"
	"315A"="2740Z"
	"315B"="2740Z"
	"315C"="2740Z"
	"316A"="2740Z"
	"316C"="2599B"
	"316D"="2344Z"
	"321A"="2611Z"
	"321C"="2611Z"
	"321D"="2612Z"
	"322A"="2630Z"
	"322B"="2630Z"
	"323Z"="2620Z"
	"331A"="2660Z"
	"331B"="2660Z"
	"332A"="2651A"
	"332B"="2651B"
	"333Z"="3320C"
	"334A"="3250B"
	"334B"="2670Z"
	"335Z"="2652Z"
	"341Z"="2892Z"
	"342A"="2920Z"
	"342B"="2920Z"
	"343Z"="2811Z"
	"351A"="3011Z"
	"351B"="3011Z"
	"351C"="3011Z"
	"351E"="3012Z"
	"352Z"="3020Z"
	"353A"="2899B"
	"353B"="3030Z"
	"353C"="3030Z"
	"354A"="3091Z"
	"354C"="3092Z"
	"354E"="3092Z"
	"355Z"="2822Z"
	"361A"="2932Z"
	"361C"="2823Z"
	"361E"="3102Z"
	"361G"="3109B"
	"361H"="3109B"
	"361J"="3109B"
	"361K"="3109B"
	"361M"="3103Z"
	"362A"="3211Z"
	"362C"="3212Z"
	"363Z"="3220Z"
	"364Z"="3230Z"
	"365Z"="2640Z"
	"366A"="3213Z"
	"366C"="3291Z"
	"366E"="1399Z"
	"371Z"="3831Z"
	"372Z"="3831Z"
	"401A"="3511Z"
	"401C"="3512Z"
	"401E"="3513Z"
	"402A"="3521Z"
	"402C"="3522Z"
	"403Z"="3530Z"
	"410Z"="3600Z"
	"451A"="4311Z"
	"451B"="4312B"
	"451D"="4313Z"
	"452A"="4120A"
	"452B"="4120B"
	"452C"="4120B"
	"452D"="4212Z"
	"452E"="4221Z"
	"452F"="4222Z"
	"452J"="4391B"
	"452K"="4399A"
	"452L"="4391A"
	"452N"="4212Z"
	"452P"="4120B"
	"452R"="4221Z"
	"452T"="4399B"
	"452U"="3900Z"
	"452V"="4399C"
	"453A"="4321A"
	"453C"="4329A"
	"453E"="4322A"
	"453F"="4322B"
	"453H"="4321B"
	"454A"="4331Z"
	"454C"="4332A"
	"454D"="4332B"
	"454F"="4333Z"
	"454H"="4334Z"
	"454J"="4334Z"
	"454L"="4332C"
	"454M"="4339Z"
	"455Z"="4399E"
	"501Z"="4511Z"
	"502Z"="4520A"
	"503A"="4531Z"
	"503B"="4532Z"
	"504Z"="4540Z"
	"505Z"="4730Z"
	"511A"="4611Z"
	"511C"="4612B"
	"511E"="4613Z"
	"511G"="4614Z"
	"511J"="4615Z"
	"511L"="4616Z"
	"511N"="4617B"
	"511P"="4617A"
	"511R"="4618Z"
	"511T"="4619B"
	"511U"="4612A"
	"512A"="4621Z"
	"512C"="4622Z"
	"512E"="4623Z"
	"512G"="4624Z"
	"512J"="4621Z"
	"513A"="1039A"
	"513C"="4632A"
	"513D"="4632B"
	"513E"="4632C"
	"513G"="4633Z"
	"513J"="1101Z"
	"513L"="4635Z"
	"513N"="4636Z"
	"513Q"="4637Z"
	"513S"="4638A"
	"513T"="4638B"
	"513V"="4639A"
	"513W"="4639B"
	"514A"="4641Z"
	"514C"="4642Z"
	"514D"="4642Z"
	"514F"="4643Z"
	"514H"="4644Z"
	"514J"="4644Z"
	"514L"="4645Z"
	"514N"="4646Z"
	"514Q"="4649Z"
	"514R"="4649Z"
	"514S"="4643Z"
	"515A"="4671Z"
	"515C"="4672Z"
	"515E"="4673A"
	"515F"="4673A"
	"515H"="4674A"
	"515J"="4674B"
	"515L"="4675Z"
	"515N"="4676Z"
	"515Q"="4677Z"
	"518A"="4662Z"
	"518C"="4663Z"
	"518E"="4664Z"
	"518G"="4651Z"
	"518H"="4665Z"
	"518J"="4652Z"
	"518L"="4669A"
	"518M"="4669B"
	"518N"="4669C"
	"518P"="4661Z"
	"519A"="4690Z"
	"519B"="4690Z"
	"521A"="4711A"
	"521B"="4711B"
	"521C"="4711C"
	"521D"="4711D"
	"521E"="4711E"
	"521F"="4711F"
	"521H"="4719A"
	"521J"="4719B"
	"522A"="4721Z"
	"522C"="4722Z"
	"522E"="4723Z"
	"522G"="4724Z"
	"522J"="4725Z"
	"522L"="4726Z"
	"522N"="4729Z"
	"522P"="4721Z"
	"523A"="4773Z"
	"523C"="4774Z"
	"523E"="4775Z"
	"524A"="4751Z"
	"524C"="4771Z"
	"524E"="4772A"
	"524F"="4772B"
	"524H"="4759A"
	"524J"="4753Z"
	"524L"="4743Z"
	"524N"="4752A"
	"524P"="4752B"
	"524R"="4761Z"
	"524T"="4778A"
	"524U"="4753Z"
	"524V"="4777Z"
	"524W"="4764Z"
	"524X"="4776Z"
	"524Y"="4778B"
	"524Z"="4741Z"
	"525Z"="4779Z"
	"526A"="4791A"
	"526B"="4791B"
	"526D"="4781Z"
	"526E"="4782Z"
	"526G"="4799A"
	"526H"="4799B"
	"527A"="9523Z"
	"527C"="9521Z"
	"527D"="9522Z"
	"527F"="9525Z"
	"527H"="9512Z"
	"551A"="5510Z"
	"551C"="5510Z"
	"551E"="5510Z"
	"552A"="5520Z"
	"552C"="5530Z"
	"552E"="5510Z"
	"552F"="5590Z"
	"553A"="5610A"
	"553B"="5610C"
	"554A"="5630Z"
	"554B"="5630Z"
	"554C"="5630Z"
	"555A"="5629B"
	"555C"="5629A"
	"555D"="5621Z"
	"601Z"="4910Z"
	"602A"="4931Z"
	"602B"="4939A"
	"602C"="4931Z"
	"602E"="4932Z"
	"602G"="4939B"
	"602L"="4941B"
	"602M"="4941A"
	"602N"="4942Z"
	"602P"="4941C"
	"603Z"="4950Z"
	"611A"="5010Z"
	"611B"="5010Z"
	"612Z"="5030Z"
	"621Z"="5110Z"
	"622Z"="5110Z"
	"623Z"="5122Z"
	"631A"="5224A"
	"631B"="5224B"
	"631D"="5210A"
	"631E"="5210B"
	"632A"="4932Z"
	"632C"="5222Z"
	"632E"="5223Z"
	"633Z"="7911Z"
	"634A"="5229A"
	"634B"="5229B"
	"634C"="5229B"
	"641A"="5310Z"
	"641C"="5320Z"
	"642C"="6110Z"
	"642D"="6110Z"
	"651A"="6411Z"
	"651C"="6419Z"
	"651D"="6419Z"
	"651E"="6419Z"
	"651F"="6419Z"
	"652A"="6491Z"
	"652C"="6492Z"
	"652E"="6420Z"
	"652F"="6499Z"
	"660A"="6511Z"
	"660C"="6520Z"
	"660E"="6512Z"
	"660F"="6520Z"
	"660G"="6512Z"
	"671A"="6611Z"
	"671C"="6612Z"
	"671E"="6612Z"
	"672Z"="6621Z"
	"701A"="4110A"
	"701B"="4110B"
	"701C"="4110C"
	"701D"="4110D"
	"701F"="6810Z"
	"702A"="6820A"
	"702B"="6820B"
	"702C"="6820B"
	"703A"="6831Z"
	"703C"="6832A"
	"703D"="6832A"
	"703E"="6619A"
	"711A"="7711A"
	"711B"="7711B"
	"712A"="7712Z"
	"712C"="7734Z"
	"712E"="7735Z"
	"713A"="7731Z"
	"713C"="7732Z"
	"713E"="7733Z"
	"713G"="7739Z"
	"714A"="7729Z"
	"714B"="7721Z"
	"721Z"="6202A"
	"722A"="5821Z"
	"722C"="6201Z"
	"723Z"="6203Z"
	"724Z"="5811Z"
	"725Z"="3312Z"
	"726Z"="6209Z"
	"731Z"="7211Z"
	"732Z"="7220Z"
	"741A"="6910Z"
	"741C"="6920Z"
	"741E"="7320Z"
	"741G"="0240Z"
	"741J"="6420Z"
	"742A"="7111Z"
	"742B"="7112A"
	"742C"="7112B"
	"743A"="7120A"
	"743B"="7120B"
	"744A"="7311Z"
	"744B"="7311Z"
	"745A"="7810Z"
	"745B"="7820Z"
	"746Z"="7490B"
	"747Z"="8121Z"
	"748A"="7420Z"
	"748B"="7420Z"
	"748D"="8292Z"
	"748F"="7430Z"
	"748G"="8219Z"
	"748H"="8220Z"
	"748J"="8230Z"
	"748K"="4779Z"
	"751A"="8411Z"
	"751C"="8412Z"
	"751E"="8413Z"
	"751G"="8110Z"
	"752A"="8421Z"
	"752C"="8422Z"
	"752E"="8423Z"
	"752G"="8424Z"
	"752J"="8425Z"
	"753A"="8430A"
	"753B"="8430B"
	"753C"="8430C"
	"801Z"="8510Z"
	"802A"="8531Z"
	"802C"="8532Z"
	"803Z"="8541Z"
	"804A"="8532Z"
	"804C"="8532Z"
	"804D"="8552Z"
	"851A"="8610Z"
	"851C"="8621Z"
	"851E"="8623Z"
	"851G"="8690D"
	"851H"="8690E"
	"851J"="8690A"
	"851K"="8690B"
	"851L"="8690C"
	"852Z"="7500Z"
	"853A"="8710B"
	"853B"="8710B"
	"853C"="8710C"
	"853D"="8710A"
	"853E"="8720A"
	"853G"="8891A"
	"853H"="8810B"
	"853J"="8810A"
	"853K"="8899A"
	"900A"="3700Z"
	"900B"="3811Z"
	"900E"="3812Z"
	"900G"="3811Z"
	"911A"="9411Z"
	"911C"="9412Z"
	"912Z"="9420Z"
	"913A"="9491Z"
	"913C"="9492Z"
	"913E"="9499Z"
	"921A"="5911A"
	"921B"="5911B"
	"921C"="5911C"
	"921D"="5911C"
	"921F"="5913A"
	"921G"="5913B"
	"921J"="5914Z"
	"922A"="5920Z"
	"922B"="5911A"
	"922D"="6020A"
	"922E"="6020B"
	"922F"="6110Z"
	"923A"="9001Z"
	"923B"="9002Z"
	"923D"="7990Z"
	"923F"="9321Z"
	"923K"="7990Z"
	"924Z"="6391Z"
	"925A"="9101Z"
	"925C"="9102Z"
	"925E"="9104Z"
	"926A"="9311Z"
	"926C"="7990Z"
	"927A"="9200Z"
	"927C"="0162Z"
	"930A"="9601A"
	"930B"="9601B"
	"930D"="9602A"
	"930E"="9602B"
	"930G"="9603Z"
	"930H"="9603Z"
	"930K"="9604Z"
	"930L"="9313Z"
	"930N"="8551Z"
	"950Z"="9700Z"
	"960Z"="9810Z"
	"970Z"="9820Z"
	"990Z"="9900Z"
	"0320"="0321Z"
"2202"="2830Z"
"4107"="1103Z"
"5510"="8130Z"
"5560"="4399C"
"5571"="4332B"
"5701"="4611Z"
"6007"="4611Z"
"6211"="4711B"
"6241"="4721Z"
"6411"="4771Z"
"6414"="4751Z"
"6425"="4719B"
"6502"="4730Z"
"6702"="5629A"
"7708"="6910Z"
"7712"="4339Z"
"7713"="7820Z"
"7715"="9412Z"
"8111"="6820A"
"8121"="6820B"
"8206"="8553Z"
"8410"="8621Z"
"8503"="8710C"
"8606"="9001Z"
"8608"="9002Z"
"8610"="8531Z"
"8804"="6512Z"
"9011"="8411Z"
"9012"="8413Z"
"9212"="8520Z"
"9214"="8531Z"
"9616"="9329Z"
"9625"="9312Z"
"9722"="9491Z"
"9723"="9499Z"
"271Z"="2410Z"
"273J"="2445Z"
"282A"="2529Z"
"282B"="2529Z"
"287M"="2572Z"
"287P"="2599B"
"291C"="2813Z"
"292K"="2829B"
"295C"="2892Z"
"295P"="2899B"
"321B"="2611Z"
"401Z"="2511Z"
"402Z"="3521Z"
"516A"="4662Z"
"516C"="4663Z"
"516E"="4664Z"
"516G"="4651Z"
"516J"="4669A"
"516K"="4669B"
"516L"="4669C"
"516N"="4661Z"
"517Z"="4690Z"
"551D"="5590Z"
"642A"="6110Z"
"642B"="6190Z"
"711Z"="7711A"
"722Z"="5829C"
"900C"="3822Z"
"922C"="6020A"
"923H"="9329Z"
"923J"="9001Z"
	;

	value $div03_sect03_
	"01"="A"
	"02"="A"
	"05"="B"
	"10"="C"
	"11"="C"
	"12"="C"
	"13"="C"
	"14"="C"
	"15"="D"
	"16"="D"
	"17"="D"
	"18"="D"
	"19"="D"
	"20"="D"
	"21"="D"
	"22"="D"
	"23"="D"
	"24"="D"
	"25"="D"
	"26"="D"
	"27"="D"
	"28"="D"
	"29"="D"
	"30"="D"
	"31"="D"
	"32"="D"
	"33"="D"
	"34"="D"
	"35"="D"
	"36"="D"
	"37"="D"
	"40"="E"
	"41"="E"
	"45"="F"
	"50"="G"
	"51"="G"
	"52"="G"
	"55"="H"
	"60"="I"
	"61"="I"
	"62"="I"
	"63"="I"
	"64"="I"
	"65"="J"
	"66"="J"
	"67"="J"
	"70"="K"
	"71"="K"
	"72"="K"
	"73"="K"
	"74"="K"
	"75"="L"
	"80"="M"
	"85"="N"
	"90"="O"
	"91"="O"
	"92"="O"
	"93"="O"
	"95"="P"
	"96"="P"
	"97"="P"
	"99"="Q"
	;

	value $sect03_ag
	"A"-"D"="AD"
	"E"-"F"="EF"
	"G"-"H"="GH"
	"I"="I"
	"J"="J"
	"K"="K"
	"L"-"M"="LM"
	"N"="N"
	"O"-"Q"="OPQ"
	OTHER="OPQ";
	;

	VALUE rk
	0.00-0.25="1.F0025"
	0.25-0.75="2.F2575"
	0.75-0.90="3.F7590"
	0.90-0.99="4.F9099" 
	0.99-1.00="5.F9910";

	VALUE decile
	0.0-0.1="d0"
	0.1-0.2="d1"
	0.2-0.3="d2"
	0.3-0.4="d3"
	0.4-0.5="d4"
	0.5-0.6="d5"
	0.6-0.7="d6"
	0.7-0.8="d7"
	0.8-0.9="d8"
	0.9-1.0="d9";

	VALUE age
	00-30="age15-30"
	31-40="age31-40"
	41-55="age41-55"
	56-199="age>=56" ;

	value $orgsizeb
	"00","01","02","03"="size_0-19"
	"04"="size_20-49"
	"05"="size_50-99"
	"06"="size_100-199"
	"07"="size_200-499" 
	"08"="size_500-999" 
	"09","10","11"="size_>1000" 
	;

	value orgsize
	0="orgsize0"
	1="orgsize1"
	2-20="orgsize2"
	21-50="orgsize20"
	51-100="orgsize50"
	101-200="orgsize100"
	201-500="orgsize200"
	501-1000="orgsize500" 
	1001-2500="orgsize1000" 
	2501-5000="orgsize2500" 
	5001-10000="orgsize5000" 
	10001-10000000="orgsize10000_plus"
	;
run;

%macro seg2(b);

	%if &b=b1994_1 %then %let year=1993.1;
	%else %if &b=b2002_1 %then %let year=2001.1;
	%else %if &b=b2009_1 %then %let year=2008.1;
	%else %let year=%substr(&b,2,4);

	%let psyear=&year;
	%if &year<1995 %then %let psyear=1995;
	%if &year=2001.1 %then %let psyear=2002;
	%if &year=2008.1 %then %let psyear=2009;

	%let year2=%substr(&psyear,3,2);

	proc sort data=&b ; 
				by IDENT_S DESCENDING wage; 
	run;

	data &b.1; set &b;
		by IDENT_S;
		if first.IDENT_S;
	run;

	PROC DATASETS LIBRARY=user; 
			DELETE &b;
	RUN;

	PROC DATASETS LIBRARY=user; 
			CHANGE &b.1=&b;
	RUN;

	* CORRECTION OF MIGRANT STATUS FROM FULL PANEL;
	proc sql; 
		%if &year>=1995 %then %do;
			create table &b.1  (rename=(migrant_def=migrant 
										/*foreign_def=noncitizen
										domtom_def=domtom*/))
			as select * from &b (rename=(migrant=migrant_old 
										nonmigrant=nonmigrant_old 
										/*noncitizen=noncitizen_old
										citizen=citizen_old
										domtom=domtom_old */)) 
			as aa
			left join psid.psid_&psyear (keep=ident_s&year2 ident_all migrant_def 
			/*domtom_def foreign_def foreign_nat_origin EU_nat_origin gets_french_nat*/)
			as bb
			on aa.ident_s=bb.ident_s&year2;
		%end;
		%else %do;
				create table &b.1  (rename=(migrant_def=migrant 
										/*foreign_def=noncitizen
										domtom_def=domtom*/))
			as select * from &b (rename=(migrant=migrant_old 
										nonmigrant=nonmigrant_old 
										/*noncitizen=noncitizen_old
										citizen=citizen_old
										domtom=domtom_old */)) 
			as aa
			left join psid.psid_1995 (keep=ident_s94 ident_all migrant_def 
			/*domtom_def foreign_def foreign_nat_origin EU_nat_origin gets_french_nat*/)
			as bb
			on aa.ident_s=bb.ident_s94;

		%end;
		quit;

		proc datasets LIBRARY=user; 
			DELETE &b ;
		RUN;


		data &b.2; set &b.1;
			if migrant=. then migrant=migrant_old;
			/*if noncitizen=. then noncitizen=noncitizen_old;
			if domtom=. then domtom=domtom_old;*/
			if ident_all=. then ident_all=ident_s*100+&year2;
			nonmigrant=1-migrant;
			/*citizen=1-noncitizen;
			nondomtom=1-domtom;
			nonEU=(noncitizen=1 and EU_nat_origin NE 1)*1;
			EU=1-noncitizen-nonEU;*/
			DROP IDENT_S ident_s&year2 nonmigrant_old migrant_old nonmigrant;
		run;

		proc datasets LIBRARY=user; 
			DELETE &b.1;
		RUN;

		PROC DATASETS LIBRARY=user; 
			CHANGE &b.2=&b;
		RUN;

		%macro analysis(unit);
			proc sql; 
			create table &b.1 as select *, 
			SUM ((included=1)) as &unit._nb,
			SUM (weight*(included=1)) as &unit._weight
			from &b group by &unit.;
			quit;

			proc means data=&b.1; 
			Title "&year. &unit Selection Descriptives";
			var wage;
			class included ;
			types included ;
			weight weight;
			run;

			proc sort data=&b.1 ; 
				by wage
				random; 
			run;

			data  &b.2; set &b.1 (where=(included=1 and &unit._nb>1 and missing(&unit)=0 )) 
									end=last; 
				sumweight + weight ;
				if last then call symput ('SUM', trim(left(put(sumweight, best.))));
			run;

			proc datasets LIBRARY=user; 
				DELETE &b &b.1;
			RUN;



			data &b.3; set &b.2;
				rk=sumweight/&SUM;
				fwage=PUT(rk,rk.);
				DROP included sumweight weight est_weight random;
			run;

			proc datasets LIBRARY=user; 
				DELETE &b.2;
			RUN;

			PROC DATASETS LIBRARY=user; 
				CHANGE &b.3=&b;
			RUN;

		%mend;

		%analysis(est);
%mend;


%macro common;
if siren NOT in ("","0","000000000","00000000");

if year<=2001 then siret=compress(""!!compress(substr(siren,2,9)!!substr(nic,2,5))!!"");
else siret=compress(""!!compress(siren!!nic)!!"");

weight=1;
*myid=_N_;

*THRESHOLD DEFINITION THANKS TO MINIMUM WAGE ;
if round(year,1)=1976 then smic=8.94; 
else if round(year,1)=1977 then smic=10.06; 
else if round(year,1)=1978 then smic=11.31; 
else if round(year,1)=1979 then smic=12.93; 
else if round(year,1)=1980 then smic=14.79; 
else if round(year,1)=1980 then smic=14.79; 
else if round(year,1)=1981 then smic=17.76;
else if round(year,1)=1982 then smic=20.29;
else if round(year,1)=1983 then smic=22.33;
else if round(year,1)=1984 then smic=24.36;
else if round(year,1)=1985 then smic=26.04;
else if round(year,1)=1986 then smic=26.92;
else if round(year,1)=1987 then smic=27.84;
else if round(year,1)=1988 then smic=28.76;
else if round(year,1)=1989 then smic=29.91;
else if round(year,1)=1990 then smic=31.94;
else if round(year,1)=1991 then smic=32.66;
else if round(year,1)=1992 then smic=34.06;
else if round(year,1)=1993 then smic=34.83;
else if round(year,1)=1994 then smic=35.56;
else if round(year,1)=1995 then smic=36.98;
else if round(year,1)=1996 then smic=37.91;
else if round(year,1)=1997 then smic=39.43;
else if round(year,1)=1998 then smic=40.22;
else if round(year,1)=1999 then smic=40.72;
else if round(year,1)=2000 then smic=42.02/6.55957;
else if round(year,1)=2001 then smic=43.72/6.55957;
else if round(year,1)=2002 then smic=6.83;
else if round(year,1)=2003 then smic=7.19;
else if round(year,1)=2004 then smic=7.61;
else if round(year,1)=2005 then smic=8.03;
else if round(year,1)=2006 then smic=8.27;
else if round(year,1)=2007 then smic=8.44;
else if round(year,1)=2008 then smic=8.63;
else if round(year,1)=2009 then smic=8.82;
else if round(year,1)=2010 then smic=8.86;
else if round(year,1)=2011 then smic=9.19;
else if round(year,1)=2012 then smic=9.40;
else if round(year,1)=2013 then smic=9.43;
else if round(year,1)=2014 then smic=9.53;
else if round(year,1)=2015 then smic=9.61;
else if round(year,1)=2016 then smic=9.67;
else if round(year,1)=2017 then smic=9.88;
else if round(year,1)=2018 then smic=9.88;
else if round(year,1)=2019 then smic=10.03;
else if round(year,1)=2020 then smic=10.15;
else if round(year,1)=2021 then smic=10.25;

threshold=0.5*smic*1600; * Redefine selection threshold according to your data / 1600 => in France, number of hours a year at 35 hours ;
included=(threshold<=S_BRUT<=smic*1600*1000 );
if included=1 then lnwage=log(s_brut);

random=ranuni(15467);

*GENDER DEFINITION;
female=(sexe=2);

*MIGRANT ORIGIN DEFINITION;
if MISSING(DEP_NAISS)=0 then migrant=(DEP_NAISS="99")*1;
nonmigrant=1-migrant;

*SECTORS DEFINITION;
length sector $5.;
if year<2008 then sector=PUT(APET,$naf03_naf08_.); 
else sector=APET; 

if year<2008 then sector_agg=PUT(substr(PUT(sector,$naf03_naf08_.),1,2), $ind08_sectagg.); 
else sector_agg=PUT(substr(sector,1,2), $ind08_sectagg.); 

*REGIONAL VARIABLES DEFINITION;
*nuts1=put(substr(COMT,1,2),$ZEAT.);
*nuts3=substr(COMT,1,2);

*RANDOM VARIABLE (For sorting);
Random=RANUNI(124567);

*Inclusion/exclusion;
if 0<S_BRUT<300000000;

* Agriculture trees & wood exploitation exclusion (but not fisheries, etc.);
* THIS is partly due to time inconsistencies in French data on agricultural firms (specific social security);
if substr(APET,1,2) not in ("","00","01","02");

rename siren=firm siret=est S_BRUT=wage comt=wtown comr=ltown;

DROP NIC DUREE SMIC DEP_NAISS 
	 REGT SEXE /*education*/ 
	 APET threshold 
	; 
%mend;


%macro b_9401(year);
	%let year2=%substr(&year,3,2);
		%macro b_reg(reg);
			DATA b&reg._&year2; 
				SET po&year..post&reg.&year2 
					(RENAME=(ETRANG=ETRANGER DEPNAI=DEP_NAISS REG=REGT CS2=CS COMR=COMR_ BRUT=S_BRUT CIPDZ=CPFD) 
						KEEP=COMR COM DEPR DEP BRUT SIREN DEPNAI CIPDZ APET 
							AGE SEXE ETRANG CS2 NIC REG NBHEUR DUREE);
				ident_s=_N_*100+REGT;
			RUN;
		%mend;
	%b_reg(reg=11);
	%b_reg(reg=21);
	%b_reg(reg=22);
	%b_reg(reg=23);
	%b_reg(reg=24);
	%b_reg(reg=25);
	%b_reg(reg=26);
	%b_reg(reg=31);
	%b_reg(reg=41);
	%b_reg(reg=42);
	%b_reg(reg=43);
	%b_reg(reg=52);
	%b_reg(reg=53);
	%b_reg(reg=54);
	%b_reg(reg=72);
	%b_reg(reg=73);
	%b_reg(reg=74);
	%b_reg(reg=82);
	%b_reg(reg=83);
	%b_reg(reg=91);
	%b_reg(reg=93);
	%b_reg(reg=94);

	DATA b&year; 
	set 
	b11_&year2 (WHERE=(REGT="11" ))
	b21_&year2 (WHERE=(REGT="21" ))
	b22_&year2 (WHERE=(REGT="22" ))
	b23_&year2 (WHERE=(REGT="23" ))
	b24_&year2 (WHERE=(REGT="24" ))
	b25_&year2 (WHERE=(REGT="25" ))
	b26_&year2 (WHERE=(REGT="26" ))
	b31_&year2 (WHERE=(REGT="31" ))
	b41_&year2 (WHERE=(REGT="41" ))
	b42_&year2 (WHERE=(REGT="42" ))
	b43_&year2 (WHERE=(REGT="43" ))
	b52_&year2 (WHERE=(REGT="52" ))
	b53_&year2 (WHERE=(REGT="53" ))
	b54_&year2 (WHERE=(REGT="54" ))
	b72_&year2 (WHERE=(REGT="72" ))
	b73_&year2 (WHERE=(REGT="73" ))
	b74_&year2 (WHERE=(REGT="74" ))
	b82_&year2 (WHERE=(REGT="82" ))
	b83_&year2 (WHERE=(REGT="83" ))
	b91_&year2 (WHERE=(REGT="91" ))
	b93_&year2 (WHERE=(REGT="93" ))
	b94_&year2 (WHERE=(REGT="94" ))
	;
	COMR=DEPR!!COMR_;
	COMT=DEP!!COM;
	year=&year;
	%common;
	drop COMR_ COM DEPR DEP;
	run;

	PROC DATASETS library=user;
		DELETE 
		b11_&year2
		b21_&year2
		b22_&year2
		b23_&year2
		b24_&year2
		b25_&year2
		b26_&year2
		b31_&year2
		b41_&year2
		b42_&year2
		b43_&year2
		b52_&year2
		b53_&year2
		b54_&year2
		b72_&year2
		b73_&year2
		b74_&year2
		b82_&year2
		b83_&year2
		b91_&year2
		b93_&year2
		b94_&year2;
	RUN;
%mend;


%macro b_94_1(year);
	%let year2=%substr(&year,3,2);
		%macro b_reg(reg);
			DATA b&reg._&year2; 
				SET po&year..post&reg.&year2 
					(RENAME=(ETRANG=ETRANGER DEPNAI=DEP_NAISS REG=REGT CS_1=CS BRUT_1=S_BRUT CIPDZ_1=CPFD NBHEUR_1=NBHEUR DUREE_1=DUREE) 
						keep=COMR_1 COM DEPR_1 DEP BRUT_1 SIREN DEPNAI CIPDZ_1 APET AGE SEXE ETRANG CS_1 NIC REG NBHEUR_1 DUREE_1);
				ident_s=_N_*100+REGT;
			RUN;
		%mend;
	%b_reg(reg=11);
	%b_reg(reg=21);
	%b_reg(reg=22);
	%b_reg(reg=23);
	%b_reg(reg=24);
	%b_reg(reg=25);
	%b_reg(reg=26);
	%b_reg(reg=31);
	%b_reg(reg=41);
	%b_reg(reg=42);
	%b_reg(reg=43);
	%b_reg(reg=52);
	%b_reg(reg=53);
	%b_reg(reg=54);
	%b_reg(reg=72);
	%b_reg(reg=73);
	%b_reg(reg=74);
	%b_reg(reg=82);
	%b_reg(reg=83);
	%b_reg(reg=91);
	%b_reg(reg=93);
	%b_reg(reg=94);

	DATA b&year._1; 
	set 
	b11_&year2 (WHERE=(REGT="11" ))
	b21_&year2 (WHERE=(REGT="21" ))
	b22_&year2 (WHERE=(REGT="22" ))
	b23_&year2 (WHERE=(REGT="23" ))
	b24_&year2 (WHERE=(REGT="24" ))
	b25_&year2 (WHERE=(REGT="25" ))
	b26_&year2 (WHERE=(REGT="26" ))
	b31_&year2 (WHERE=(REGT="31" ))
	b41_&year2 (WHERE=(REGT="41" ))
	b42_&year2 (WHERE=(REGT="42" ))
	b43_&year2 (WHERE=(REGT="43" ))
	b52_&year2 (WHERE=(REGT="52" ))
	b53_&year2 (WHERE=(REGT="53" ))
	b54_&year2 (WHERE=(REGT="54" ))
	b72_&year2 (WHERE=(REGT="72" ))
	b73_&year2 (WHERE=(REGT="73" ))
	b74_&year2 (WHERE=(REGT="74" ))
	b82_&year2 (WHERE=(REGT="82" ))
	b83_&year2 (WHERE=(REGT="83" ))
	b91_&year2 (WHERE=(REGT="91" ))
	b93_&year2 (WHERE=(REGT="93" ))
	b94_&year2 (WHERE=(REGT="94" ))
	;
	COMR=DEPR_1!!COMR_1;
	COMT=DEP!!COM;
	year=&year-0.9;
	age=age-1;
	CS=SUBSTR(CS,1,2);
	%common;
	drop COMR_1 COM DEPR_1 DEP;
	run;

	PROC DATASETS library=user;
		DELETE 
		b11_&year2
		b21_&year2
		b22_&year2
		b23_&year2
		b24_&year2
		b25_&year2
		b26_&year2
		b31_&year2
		b41_&year2
		b42_&year2
		b43_&year2
		b52_&year2
		b53_&year2
		b54_&year2
		b72_&year2
		b73_&year2
		b74_&year2
		b82_&year2
		b83_&year2
		b91_&year2
		b93_&year2
		b94_&year2;
	RUN;
%mend;

%macro b_0208(year);
	%let keep=IDENT_S SIREN NIC S_BRUT DUREE REGT APET DEP_NAISS AGE SEXE CS TYP_EMPLOI ;
	%let year2=%substr(&year,3,2);
	%let where=TYP_EMPLOI NOT IN ("E","I") and DUREE>359 ;

	data b&year; 
		set 
		po&year..post11&year2 (KEEP=&keep WHERE=(REGT="11" AND &where )) 
		po&year..post21&year2 (KEEP=&keep WHERE=(REGT="21" AND &where )) 
		po&year..post22&year2 (KEEP=&keep WHERE=(REGT="22" AND &where )) 
		po&year..post23&year2 (KEEP=&keep WHERE=(REGT="23" AND &where )) 
		po&year..post24&year2 (KEEP=&keep WHERE=(REGT="24" AND &where )) 
		po&year..post25&year2 (KEEP=&keep WHERE=(REGT="25" AND &where )) 
		po&year..post26&year2 (KEEP=&keep WHERE=(REGT="26" AND &where )) 
		po&year..post31&year2 (KEEP=&keep WHERE=(REGT="31" AND &where )) 
		po&year..post41&year2 (KEEP=&keep WHERE=(REGT="41" AND &where )) 
		po&year..post42&year2 (KEEP=&keep WHERE=(REGT="42" AND &where )) 
		po&year..post43&year2 (KEEP=&keep WHERE=(REGT="43" AND &where )) 
		po&year..post52&year2 (KEEP=&keep WHERE=(REGT="52" AND &where )) 
		po&year..post53&year2 (KEEP=&keep WHERE=(REGT="53" AND &where )) 
		po&year..post54&year2 (KEEP=&keep WHERE=(REGT="54" AND &where )) 
		po&year..post72&year2 (KEEP=&keep WHERE=(REGT="72" AND &where )) 
		po&year..post73&year2 (KEEP=&keep WHERE=(REGT="73" AND &where )) 
		po&year..post74&year2 (KEEP=&keep WHERE=(REGT="74" AND &where )) 
		po&year..post82&year2 (KEEP=&keep WHERE=(REGT="82" AND &where )) 
		po&year..post83&year2 (KEEP=&keep WHERE=(REGT="83" AND &where )) 
		po&year..post91&year2 (KEEP=&keep WHERE=(REGT="91" AND &where ))
		po&year..post93&year2 (KEEP=&keep WHERE=(REGT="93" AND &where ))
		po&year..post94&year2 (KEEP=&keep WHERE=(REGT="94" AND &where )) 
		;
		year=&year;
		%common;
		drop TYP_EMPLOI DUREE;
	run;
%mend;


%macro b_02_1(year);
	%let year2=%substr(&year,3,2);
	%let rename= CS_1=CS APET_1=APET COMR_1=COMR COMT_1=COMT ETRANGER_1=ETRANGER S_BRUT_1=S_BRUT CPFD_1=CPFD REGT_1=REGT NBHEUR_1=NBHEUR DUREE_1=DUREE;
	%let keep= COMR_1 COMT_1 S_BRUT_1 SIREN IDENT_S DEP_NAISS CPFD_1 APET_1 TYP_EMPLOI_1 AGE SEXE ETRANGER_1 CS_1 NIC REGT_1 NBHEUR_1 DUREE_1;
	%let where=TYP_EMPLOI NOT IN ("E","I") and DUREE>359 ;
	data b&year._1; 
	set 
	po&year..post11&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="11" AND &where )) 
	po&year..post21&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="21" AND &where )) 
	po&year..post22&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="22" AND &where )) 
	po&year..post23&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="23" AND &where )) 
	po&year..post24&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="24" AND &where )) 
	po&year..post25&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="25" AND &where )) 
	po&year..post26&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="26" AND &where )) 
	po&year..post31&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="31" AND &where )) 
	po&year..post41&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="41" AND &where )) 
	po&year..post42&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="42" AND &where )) 
	po&year..post43&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="43" AND &where )) 
	po&year..post52&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="52" AND &where )) 
	po&year..post53&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="53" AND &where )) 
	po&year..post54&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="54" AND &where )) 
	po&year..post72&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="72" AND &where )) 
	po&year..post73&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="73" AND &where )) 
	po&year..post74&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="74" AND &where )) 
	po&year..post82&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="82" AND &where )) 
	po&year..post83&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="83" AND &where )) 
	po&year..post91&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="91" AND &where )) 
	po&year..post93&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="93" AND &where ))
	po&year..post94&year2 (RENAME=(&rename )KEEP=&keep  WHERE=(REGT="94" AND &where )) 
	;
	year=&year-0.9;
	age=age-1;
	%common;
	drop TYP_EMPLOI_1;
	run;
%mend;



%macro b_09(year);
	%let keep= COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE IND_ETRANGER PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE;
	%let rename= PCS=CS IND_ETRANGER=ETRANGER;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I") and Duree>359;
	data b&year; 
	set 
	po&year..post11aa (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where )) 
	po&year..post11bb (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where )) 
	po&year..post11cc (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where )) 
	po&year..post11dd (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where )) 
	po&year..post21 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="21" AND &where )) 
	po&year..post22 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="22" AND &where )) 
	po&year..post23 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="23" AND &where )) 
	po&year..post24 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="24" AND &where )) 
	po&year..post25 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="25" AND &where )) 
	po&year..post26 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="26" AND &where )) 
	po&year..post31 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="31" AND &where )) 
	po&year..post41 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="41" AND &where )) 
	po&year..post42 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="42" AND &where )) 
	po&year..post43 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="43" AND &where )) 
	po&year..post52 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="52" AND &where )) 
	po&year..post53 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="53" AND &where )) 
	po&year..post54 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="54" AND &where )) 
	po&year..post72 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="72" AND &where )) 
	po&year..post73 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="73" AND &where )) 
	po&year..post74 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="74" AND &where )) 
	po&year..post82 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="82" AND &where )) 
	po&year..post83 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="83" AND &where )) 
	po&year..post91 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="91" AND &where )) 
	po&year..post93 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="93" AND &where ))
	po&year..post94 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="94" AND &where )) 
	;
	year=&year;
	CS=SUBSTR(CS,1,2);
	%common;
	drop TYP_EMPLOI DOMEMPL_EMPL;
	run;
%mend;



%macro b_10(year);
	%let keep=COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE IND_ETRANGER PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE;
	%let rename= PCS=CS IND_ETRANGER=ETRANGER;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I") AND DUREE>359;
	data b&year; 
	set 
	po&year..post11aa (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where ))
	po&year..post11bb (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where ))
	po&year..post11cc (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where ))
	po&year..post11dd (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="11" AND &where ))
	po&year..post21 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="21" AND &where )) 
	po&year..post22 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="22" AND &where )) 
	po&year..post23 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="23" AND &where )) 
	po&year..post24 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="24" AND &where )) 
	po&year..post25 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="25" AND &where )) 
	po&year..post26 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="26" AND &where )) 
	po&year..post31 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="31" AND &where )) 
	po&year..post41 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="41" AND &where )) 
	po&year..post42 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="42" AND &where )) 
	po&year..post43 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="43" AND &where )) 
	po&year..post52 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="52" AND &where )) 
	po&year..post53 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="53" AND &where )) 
	po&year..post54 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="54" AND &where )) 
	po&year..post72 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="72" AND &where )) 
	po&year..post73 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="73" AND &where )) 
	po&year..post74 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="74" AND &where )) 
	po&year..post82a (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="82" AND &where )) 
	po&year..post82b (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="82" AND &where )) 
	po&year..post83 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="83" AND &where )) 
	po&year..post91 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="91" AND &where )) 
	po&year..post93 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="93" AND &where )) 
	po&year..post94 (RENAME=(&rename) KEEP=&keep  WHERE=(REGT="94" AND &where )) 
	;
	year=&year;
	CS=SUBSTR(CS,1,2);
	%common;
	drop TYP_EMPLOI DOMEMPL_EMPL;
	run;
%mend;


%macro b_11(year);
	%let keep=COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE IND_ETRANGER PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE ;
	%let rename= PCS=CS IND_ETRANGER=ETRANGER;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I") and DUREE>359;
	data b&year; 
	set 
	po&year..post11 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="11" AND &where ))
	po&year..post22 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="22" AND &where )) 
	po&year..post23 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="23" AND &where )) 
	po&year..post24 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="24" AND &where )) 
	po&year..post25 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="25" AND &where )) 
	po&year..post26 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="26" AND &where )) 
	po&year..post31 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="31" AND &where )) 
	po&year..post41 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="41" AND &where )) 
	po&year..post42 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="42" AND &where )) 
	po&year..post43 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="43" AND &where )) 
	po&year..post52 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="52" AND &where )) 
	po&year..post53 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="53" AND &where )) 
	po&year..post54 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="54" AND &where )) 
	po&year..post72 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="72" AND &where )) 
	po&year..post73 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="73" AND &where )) 
	po&year..post74 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="74" AND &where )) 
	po&year..post82 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="82" AND &where )) 
	po&year..post83 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="83" AND &where )) 
	po&year..post91 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="91" AND &where )) 
	po&year..post93 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="93" AND &where )) 
	po&year..post94 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="94" AND &where )) 
	;
	year=&year;
	CS=SUBSTR(CS,1,2);
	%common;
	drop TYP_EMPLOI DOMEMPL_EMPL;
run;
%mend;

%macro b_1213(year);
	%let keep=COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE IND_ETRANGER PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE DEPT;
	%let rename= PCS=CS IND_ETRANGER=ETRANGER;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I") and DUREE>359;
	data b&year; 
		set 
		pi&year..post75 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="75" AND &where ))
		pi&year..post77 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="77" AND &where ))
		pi&year..post78 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="78" AND &where ))
		pi&year..post91 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="91" AND &where ))
		pi&year..post92 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="92" AND &where ))
		pi&year..post93 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="93" AND &where ))
		pi&year..post94 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="94" AND &where ))
		pi&year..post95 (RENAME=(&rename) KEEP=&keep WHERE=(DEPT="95" AND &where ))

		po&year..post22 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="22" AND &where )) 
		po&year..post23 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="23" AND &where )) 
		po&year..post24 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="24" AND &where )) 
		po&year..post25 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="25" AND &where )) 
		po&year..post26 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="26" AND &where )) 
		po&year..post31 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="31" AND &where )) 
		po&year..post41 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="41" AND &where )) 
		po&year..post42 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="42" AND &where )) 
		po&year..post43 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="43" AND &where )) 
		po&year..post52 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="52" AND &where )) 
		po&year..post53 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="53" AND &where )) 
		po&year..post54 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="54" AND &where )) 
		po&year..post72 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="72" AND &where )) 
		po&year..post73 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="73" AND &where )) 
		po&year..post74 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="74" AND &where )) 
		po&year..post82 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="82" AND &where )) 
		po&year..post83 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="83" AND &where )) 
		po&year..post91 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="91" AND &where )) 
		po&year..post93 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="93" AND &where )) 
		po&year..post94 (RENAME=(&rename) KEEP=&keep WHERE=(REGT="94" AND &where )) 
		;
		year=&year;
		CS=SUBSTR(CS,1,2);
		%common;
		drop TYP_EMPLOI DOMEMPL_EMPL DEPT;
	run;
%mend;

%macro b_1417(year);
	%if &year<2016 %then %do; 
		%let IND_ETRANGER= IND_ETRANGER;
		%let rename= RENAME=(IND_ETRANGER=ETRANGER PCS=CS) ; 
	%end;
	%else %do; 
		%let IND_ETRANGER= ;
		%let rename= RENAME=(PCS=CS) ; 
	%end;
	%let keep= COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE &IND_ETRANGER PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE DEPT  ;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I") and DUREE>359 ;
	
	data b&year; 
		set 
		pi&year..post75 (&rename KEEP=&keep where=(DEPT="75" AND &where))
		pi&year..post77 (&rename KEEP=&keep where=(DEPT="77" AND &where))
		pi&year..post78 (&rename KEEP=&keep where=(DEPT="78" AND &where))
		pi&year..post91 (&rename KEEP=&keep where=(DEPT="91" AND &where))
		pi&year..post92 (&rename KEEP=&keep where=(DEPT="92" AND &where))
		pi&year..post93 (&rename KEEP=&keep where=(DEPT="93" AND &where))
		pi&year..post94 (&rename KEEP=&keep where=(DEPT="94" AND &where))
		pi&year..post95 (&rename KEEP=&keep where=(DEPT="95" AND &where))

		po&year..post24 (&rename KEEP=&keep WHERE=(REGT="24" AND &where)) 
		po&year..post27 (&rename KEEP=&keep WHERE=(REGT="27" AND &where)) 
		po&year..post28 (&rename KEEP=&keep WHERE=(REGT="28" AND &where)) 
		po&year..post32 (&rename KEEP=&keep WHERE=(REGT="32" AND &where)) 
		po&year..post44 (&rename KEEP=&keep WHERE=(REGT="44" AND &where)) 
		po&year..post52 (&rename KEEP=&keep WHERE=(REGT="52" AND &where)) 
		po&year..post53 (&rename KEEP=&keep WHERE=(REGT="53" AND &where)) 
		po&year..post75 (&rename KEEP=&keep WHERE=(REGT="75" AND &where)) 
		po&year..post76 (&rename KEEP=&keep WHERE=(REGT="76" AND &where)) 
		po&year..post84 (&rename KEEP=&keep WHERE=(REGT="84" AND &where)) 
		po&year..post93 (&rename KEEP=&keep WHERE=(REGT="93" AND &where))
		po&year..post94 (&rename KEEP=&keep WHERE=(REGT="94" AND &where))

		;
			year=&year;
		%common;		 
		drop TYP_EMPLOI DOMEMPL_EMPL;
	run;
%mend;

%macro b_1819(year);
	%let keep= 	COMR COMT S_BRUT SIREN IDENT_S DEP_NAISS CPFD APET TYP_EMPLOI AGE SEXE /*IND_ETRANGER*/ PCS NIC REGT DOMEMPL_EMPL NBHEUR DUREE DEPT  ;
	%let where=DOMEMPL_EMPL not in ("1","7") AND TYP_EMPLOI NOT IN ("E","I")  AND DEPT NOT IN ("97","98","99") and substr(COMT,1,2) NOT IN ("97","98","99") AND DUREE>359;
	%let rename=RENAME=(PCS=CS) ; 

	data b&year; 
		set 
		po&year..post_1 (&rename KEEP=&keep WHERE=(&where))
		po&year..post_2 (&rename KEEP=&keep WHERE=(&where))
		po&year..post_3 (&rename KEEP=&keep WHERE=(&where))
		po&year..post_4 (&rename KEEP=&keep WHERE=(&where))
		;
		year=&year;
			%common;		 
		CS=SUBSTR(CS,1,2);
		drop TYP_EMPLOI DOMEMPL_EMPL;
	run;
%mend;

%macro evol(y);
	%let y_1=%eval(&y-1);
	%let y_2=%eval(&y-2);
	%let y_3=%eval(&y-3);

	%let ys=%substr(&y,3,4);
	%let ys_1=%substr(&y_1,3,4);
	%let ys_2=%substr(&y_2,3,4);
	%let ys_3=%substr(&y_3,3,4);

	/*
	data lyof; set lyof.lyof&ys_2._&ys_1; 
		if effref&ys_2 NE .   and effref&ys_2 >0 then do; 
			r_lyof&ys_2=nblayoffs&ys_2/effref&ys_2;
			r_otlyof&ys_2=nbothlayoffs&ys_2/effref&ys_2;
			r_exit&ys_2=nbexits&ys_2/effref&ys_2;
		end;
		if effref&ys_1 NE . and effref&ys_1 >0  then do; 
			r_lyof&ys_1=nblayoffs&ys_1/effref&ys_1;
			r_otlyof&ys_1=nbothlayoffs&ys_1/effref&ys_1;
			r_exit&ys_1=nbexits&ys_1/effref&ys_1;
		end;

		if r_lyof&ys_2 NE . and r_lyof&ys_1 NE . then r_lyof_b=(r_lyof&ys_2+r_lyof&ys_1)/2;
			else if r_lyof&ys_2 NE . then r_lyof_b=(r_lyof&ys_2);
			else r_lyof_b=(r_lyof&ys_1);

		if r_otlyof&ys_2 NE . and r_otlyof&ys_1 NE . then r_otlyof_b=(r_otlyof&ys_2+r_otlyof&ys_1)/2;
			else if r_otlyof&ys_2 NE . then r_otlyof_b=(r_otlyof&ys_2);
			else r_otlyof_b=(r_otlyof&ys_1);

		if r_exit&ys_2 NE . and r_exit&ys_1 NE . then r_exit_b=(r_exit&ys_2+r_exit&ys_1)/2;
			else if r_exit&ys_2 NE . then r_exit_b=(r_exit&ys_2);
			else r_exit_b=(r_exit&ys_1);
		
		r_lyof=(Max(nblayoffs&ys_2,0)+Max(nblayoffs&ys_1,0))/Max(effref&ys_2,effref&ys_1);
		r_otlyof=(Max(nbothlayoffs&ys_2,0)+Max(nbothlayoffs&ys_1,0))/Max(effref&ys_2,effref&ys_1);
		r_exit=(Max(nbexits&ys_2,0)+Max(nbexits&ys_1,0))/Max(effref&ys_2,effref&ys_1);
	run;
	*/
	%if &y<2014 %then %do; 
	proc sql; 
			create table b&y.2 (drop=sirlifi) as select * from b&y as aa left join 
					lifi&ys..ent (keep=sirlifi sirtg ) 
					as bb on aa.firm=bb.sirlifi;
	quit;
	%end;
	%else %do;
	proc sql;  
			create table b&y.2 (drop=sirlifi) as select * from b&y as aa left join 
					lifi&ys..ul_lifi (keep=id_ul id_groupe rename=(id_ul=sirlifi id_groupe=sirtg )) 
					as bb on aa.firm=bb.sirlifi;
	%end;

	%if &y_3<2014 %then %do; 
		proc sql; 
				create table b&y_3.2 (drop=sirlifi) as select * from b&y_3 as aa left join 
						lifi&ys_3..ent (keep=sirlifi sirtg ) 
						as bb on aa.firm=bb.sirlifi;
		quit;
	%end; 
	%else %do; 
			proc sql; 
				create table b&y_3.2 (drop=sirlifi) as select * from b&y_3 as aa left join 
						lifi&ys_3..ul_lifi (keep=id_ul id_groupe rename=(id_ul=sirlifi id_groupe=sirtg )) 
						as bb on aa.firm=bb.sirlifi;
			quit;
	%end; 
	/*proc sql; 
		create table b&y_3.3 	as select * from b&y_32  as aa
			left join lyof (keep=est r_lyof r_otlyof r_exit) as bb on aa.est=bb.est; 
	quit;
	

	proc sql; 
		create table b&y_1fullmob (drop=ident_s&ys_1) as select * from wflow.b&y_1fullmob
				as aa
				left join psid.psid_&y_1 (keep=ident_s&ys_1 ident_all)
				as bb
				on aa.ident_s=bb.ident_s&ys_1;		
			quit;
			
	data b&y_1fullmob_2 (drop=ident_s); set b&y_1fullmob (keep=ident_all ident_s tmob ecart);
		if ident_all=. then ident_all=ident_s*100+&ys_1;
	run;
	*/

	proc sql; 
		create table fd&y as select * from  b&y.2 as aa 
					full join b&y_3.2 (keep=ident_all est sirtg lnwage rk /*r_lyof r_otlyof r_exit*/ 
								rename=(est=l3est sirtg=l3sirtg lnwage=l3lnwage rk=l3rk )) as bb
					on aa.ident_all=bb.ident_all; 
	quit;

	proc datasets library=user; 
		delete b&y_3 b&y_3.2 b&y.2;
	RUN;
	

	data fd&y.2; set fd&y; 
		if year=&y then weight=1;
		else weight=0;
		rkbis=l3rk;
		if year=&y and l3rk=. then rkbis=rk;

		if l3rk ne . and rk ne . then move=(1-(est=l3est))+(1-(substr(est,1,9)=substr(l3est,1,9)))+(1-(sirtg=l3sirtg and sirtg NE ""));
		
	run;		

	proc datasets library=user; 
		delete fd&y ;
	RUN;

	/*
	proc sql; 
		create table fd&y.2a
			as select * from fd&y.2 as aa left join b&y_1.fullmob_2 as bb 
			on aa.ident_all=bb.ident_all; 
	quit;

	proc datasets library=user; 
		delete fd&y fd&y.2;
	RUN;
	*/


	proc sort data=fd&y.2; 
		by weight rkbis; 
	run;

	data fd&y.3; set fd&y.2	end=last; 
		sumweight + weight ;
		if last then call symput ('SUMBIS', trim(left(put(sumweight, best.))));
		if l3rk ne . and rk ne . then move=(1-(est=l3est))+(1-(substr(est,1,9)=substr(l3est,1,9)))+(1-(sirtg=l3sirtg and sirtg NE ""));

		if move<3 then tmob=move;
		else if tmob=. then tmob=4;
	run;

	proc datasets library=user; 
		delete fd&y.2;
	RUN;

	data fd&y.4; set fd&y.3; 
		rkbis=sumweight/&SUMBIS; 
	run;

	proc datasets library=user; 
		delete fd&y.3;
	RUN;

	proc sql; 
		create table fd&y.5 as select *, 
					sum((rk>=0)) as countuny,
					sum((PUT(rk,rk.)="1.F0025")) as F0025uny,
					sum((PUT(rk,rk.)="2.F2575")) as F2575uny, 
					sum((PUT(rk,rk.)="4.F9099")) as F9099uny, 
					sum((PUT(rk,rk.)="5.F9910")) as F9910uny,
					sum((PUT(rkbis,rk.)="1.F0025")) as F0025uny_bis,
					sum((PUT(rkbis,rk.)="2.F2575")) as F2575uny_bis, 
					sum((PUT(rkbis,rk.)="4.F9099")) as F9099uny_bis, 
					sum((PUT(rkbis,rk.)="5.F9910")) as F9910uny_bis/*,
					mean(exp(log((lnwage-l3lnwage)*(l3est=est)))) as md3lnwage,
					mean(rk) as mrk,
					mean(rkbis) as mrkbis,
					sum((l3est=""))/sum((rk>=0)) as rarr_nm,
					sum((l3est=est))/sum((rk>=0)) as rarr_st,
					sum(tmob=1)/sum((rk>=0)) as rarr_wfirm,
					sum(tmob=2)/sum((rk>=0)) as rarr_wgp,
					sum(tmob in (3,3.1,3.2,3.3))/sum((rk>=0)) as rarr_outsourc,
					sum(tmob in (4,5,5.1) & ecart<=92)/sum((rk>=0)) as rarr_resign,
					sum(tmob  in (4,5,5.1) & ecart>92)/sum((rk>=0)) as rarr_fired*/
			from fd&y.4 group by est; 
		quit;

	proc datasets library=user; 
		delete fd&y.4;
	RUN;

	proc sql; 
		create table fd&y.6 as select *, 
					sum((l3rk>=0)) as l3countuny,
					sum((PUT(l3rk,rk.)="1.F0025")) as l3F0025uny,
					sum((PUT(l3rk,rk.)="2.F2575")) as l3F2575uny, 
					sum((PUT(l3rk,rk.)="4.F9099")) as l3F9099uny, 
					sum((PUT(l3rk,rk.)="5.F9910")) as l3F9910uny/*,
					mean(l3rk) as ml3rk,
					sum((est=""))/sum((l3rk>=0)) as rdep_nm,
					sum((est=l3est))/sum((l3rk>=0)) as rdep_st,
					sum(tmob=1)/sum((l3rk>=0)) as rdep_wfirm,
					sum(tmob=2)/sum((l3rk>=0)) as rdep_wgp,
					sum(tmob in (3,3.1,3.2,3.3))/sum((l3rk>=0)) as rdep_outsourc,
					sum(tmob in (4,5,5.1) & ecart<=92)/sum((l3rk>=0)) as rdep_resign,
					sum(tmob in (4,5,5.1) & ecart>92)/sum((l3rk>=0)) as rdep_fired*/
			from fd&y.5 group by l3est; 
	quit;

	proc datasets library=user; 
		delete fd&y.5;
	RUN;

	data fd&y.7 ; set fd&y.6;
		if countuny>0 and year=&y then do; 
			xF0025=(F0025uny-(PUT(rk,rk.)="1.F0025"))/(countuny-1);
			xF2575=(F2575uny-(PUT(rk,rk.)="2.F2575"))/(countuny-1);
			xF9099=(F9099uny-(PUT(rk,rk.)="4.F9099"))/(countuny-1);
			xF9910=(F9910uny-(PUT(rk,rk.)="5.F9910"))/(countuny-1);

			xF0025_bis=(F0025uny_bis-(PUT(rkbis,rk.)="1.F0025"))/(countuny-1);
			xF2575_bis=(F2575uny_bis-(PUT(rkbis,rk.)="2.F2575"))/(countuny-1);
			xF9099_bis=(F9099uny_bis-(PUT(rkbis,rk.)="4.F9099"))/(countuny-1);
			xF9910_bis=(F9910uny_bis-(PUT(rkbis,rk.)="5.F9910"))/(countuny-1);

			xF9010=xF9099+xF9910;
			xF9010_bis=xF9099_bis+xF9910_bis;
			

			F9010=(rk>=0.9);
			F9010_bis=(rkbis>=0.9);

			F9910=(rk>=0.99);
			F9910_bis=(rkbis>=0.99);

		end;
		if l3countuny>0 and l3rk NE . then do; 
			l3xF0025=(l3F0025uny-(PUT(l3rk,rk.)="1.F0025"))/(l3countuny-1);
			l3xF2575=(l3F2575uny-(PUT(l3rk,rk.)="2.F2575"))/(l3countuny-1);
			l3xF9099=(l3F9099uny-(PUT(l3rk,rk.)="4.F9099"))/(l3countuny-1);
			l3xF9910=(l3F9910uny-(PUT(l3rk,rk.)="5.F9910"))/(l3countuny-1);

			l3xF9010=l3xF9099+l3xF9910;
			l3F9010=(l3rk>=0.9);
			l3F9910=(l3rk>=0.99);
		end;

		d3xF9010=xF9010-l3xF9010;
		d3xF9010_bis=xF9010_bis-l3xF9010;	

		d3xF9910=xF9910-l3xF9910;
		d3xF9910_bis=xF9910_bis-l3xF9910;	

		/*
		d3xF0025=xF0025-l3xF0025;
		d3xF0025_bis=xF0025_bis-l3xF0025;	
		
		xF0075=xF0025+xF2575;
		xF0075_bis=xF0025_bis+xF2575_bis;
		l3xF0075=l3xF0025+l3xF2575;

		d3xF0075=xF0075-l3xF0075;
		d3xF0075_bis=xF0075_bis-l3xF0075;	
		d3lnwage= lnwage-l3lnwage;
		if countuny>0 and l3countuny>0 then d3lncountuny= log(countuny)-log(l3countuny);

		
		mrk=(countuny*mrk-rk)/(countuny-1);
		mrkbis=(countuny*mrkbis-rkbis)/(countuny-1);
		ml3rk=(countuny*ml3rk-l3rk)/(countuny-1);

		d3rk= rk-l3rk;
		d3mrk= mrk-ml3rk;
		d3mrkbis= mrkbis-ml3rk;

		if r_lyof=. then r_lyof=0;
		if r_otlyof=. then r_otlyof=0;
		if r_exit=. then r_exit=0;
		*/


		DROP xF2575 xF2575_bis l3xF2575;

	run;


	proc datasets library=user; 
		delete fd&y.6;
	RUN;


	
	data FD&y.7_s; set FD&y.7 (where=(l3F9010=1 or F9010=1 or F9010_BIS=1 ) );
		/*
		move0=(move=0);
		tmob2=tmob;

		if tmob in (3.1,3.2,3.3) then tmob2=3; 
		else if tmob in (4,5) and ecart<=92 then tmob2=4; 
		else if tmob in (4,5) and ecart>92 then tmob2=6;

		rdep=rdep_wfirm+rdep_wgp+rdep_outsourc+rdep_fired+rdep_resign;
		rarr=rarr_wfirm+rarr_wgp+rarr_outsourc+rarr_fired+rarr_resign;

		if countuny>0 and l3countuny>0 then d3lncountuny= log(countuny)-log(l3countuny);
		d3lncountuny_pos=max(d3lncountuny,0) ;
		d3lncountuny_neg=min(d3lncountuny,0) ;
		*/

				
	run;

	proc datasets library=user; 
		delete fd&y.7;
	RUN;



/*
	proc sql; create table FD&y7_vs as select 
									min(est) as est,
									mean(rdep_outsourc) as rdep_outsourc,
									mean(rarr_outsourc) as  rarr_outsourc,
									mean(rdep_wfirm) as rdep_wfirm,
									mean(rarr_wfirm) as  rarr_wfirm,
									mean(rdep_wgp) as rdep_wgp,
									mean(rarr_wgp) as  rarr_wgp,
									mean(rdep_resign) as rdep_resign,
									mean(rarr_resign) as  rarr_resign,
									mean(rdep_fired) as rdep_fired,
									mean(rarr_fired) as  rarr_fired,
									mean(md3lnwage) as md3lnwage,
									sum(l3f9010*f9010*move0) as f9010_st,
									sum(f9010) as f9010,
									sum(l3f9010) as l3f9010,
									mean(d3xF9010) as d3xF9010,
									mean(xF9010) as xF9010,
									mean(l3xF9010) as l3xF9010 from FD&y7_s (where=(est=l3est)) group by est; 
									quit;

*/

	***************************************;
	* ESTIMATES                           *;
	***************************************;

	/*
	proc means data=fd&y.7 (keep= tmob d3mrkbis where=(d3mrkbis NE .)); var d3mrkbis; class tmob; run;

	proc freq data=fd&y.7 (keep= move tmob); table move tmob /missing;  run;
	
	proc means; var l3xF9010 xF9010 xF9010_bis l3xF9910 xF9910 xF9910_bis countuny l3countuny; 
	run;
	*/

	proc means data=FD&y.7_s; 
		title "Top 10% isolation and evolution in T-3 (&y)";
		var l3xF9010 xF9010 xF9010_bis d3xF9010 d3xF9010_BIS;
		where l3F9010 =1; 
		output out=rec.IS90Y_3&y;
	run;

	proc means data=FD&y.7_s; 
		title "Top 10% isolation and evolution in T (&y)";
		var l3xF9010 xF9010 xF9010_bis d3xF9010 d3xF9010_BIS;
		where F9010 = 1; 
		output out=rec.IS90Y&y;
	run;

	proc means data=FD&y.7_s; 
		title "Top 10% isolation and evolution in T and T-3 pay scale (&y)";
		var l3xF9010 xF9010 xF9010_bis d3xF9010 d3xF9010_BIS;
		where F9010_bis= 1; 
		output out=rec.IS90Ybis&y;
	run;

	proc means data=FD&y.7_s; 
		title "Top 1% isolation and evolution in T-3 (&y)";
		var l3xF9910 xF9910 xF9910_bis d3xF9910 d3xF9910_BIS;;
		where l3F9910 = 1; 
		output out=rec.IS99Y_3&y;
	run;

	proc means data=FD&y.7_s; 
		title "Top 1% isolation and evolution in T (&y)";
		var l3xF9910 xF9910 xF9910_bis d3xF9910 d3xF9910_BIS;
		where F9910 = 1; 
		output out=rec.IS99Y&y;
	run;

	proc means data=FD&y.7_s; 
		title "Top 1% isolation and evolution in T and T-3 pay scale (&y)";
		var l3xF9910 xF9910 xF9910_bis d3xF9910 d3xF9910_BIS;
		where F9910_bis = 1; 
		output out=rec.IS99Ybis&y;
	run;

	proc datasets library=user; 
		delete FD&y.7_s;
	RUN;
%mend;

%b_0208(2002);%seg2(b2002);
%b_0208(2005);%seg2(b2005);
%evol(2005);

%b_0208(2008);%seg2(b2008);
%evol(2008);

%b_11(2011);%seg2(b2011);
%evol(2011);

%b_11(2011);%seg2(b2011);
%b_1417(2014);%seg2(b2014);
%evol(2014);

%b_1417(2017);%seg2(b2017);
%evol(2017);

proc datasets lib=user; 
	delete b2017;
run;
